#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

int bit[20086][1024] = {};
int lock[20086] = {};
int ipt[1024];

vector<int> sub;

int main(int argc, char const *argv[])
{
    long long rst = 0;
    int n;
    cin >> n;
    for (int i = 10000; i < 20086; i++)
    {
        for (int j = 0; j < 1024; j++)
        {
            bit[i][j] = 666666;
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        cin >> ipt[i];
        for (int j = 0; j < 20086; j++)
        {
            lock[j] = 0;
        }
        for (int j = 0; j < i; j++)
        {
            int k = ipt[i] - ipt[j] + 10000;
            if (!lock[k])
            {
                if (k > 10000)
                {
                    int *p = lower_bound(bit[k], bit[k] + 1024, ipt[i]);
                    cout << k << " " << *p << "->" << ipt[i] 
                    << "-" << ipt[j] << endl;
                    *p = ipt[i];
                    lock[k] = 1;
                }
                else if (k < 10000)
                {
                    int *p = lower_bound(bit[k], bit[k] + 1024, ipt[i], greater<int>());
                    cout << k << " " << *p << "->" << ipt[i] 
                    << "-" << ipt[j] << endl;
                    *p = ipt[i];
                    lock[k] = 1;
                }
            }
        }
    }
    for (int i = 0; i < 10000; i++)
    {
        int *p = lower_bound(bit[i], bit[i] + 1024, 0, greater<int>());
        if (p != bit[i])
        {
            cout << i << " " << *(p - 2) << " " << p - bit[i] << " " << *(p - 1);
            long long t = 1, m = p - bit[i] - 1, b = 1;
            while (m)
            {
                t += ++b;
                t %= 998244353;
                m--;
            }
            cout << " " << t << endl;
            rst += t;
            rst %= 998244353;
        }
    }
    
    for (int i = 10001; i < 20086; i++)
    {
        int *p = lower_bound(bit[i], bit[i] + 1024, 666666);
        if (p != bit[i])
        {
            cout << i << " " << *(p - 2) << " " << p - bit[i] << " " << *(p - 1);
            long long t = 1, m = p - bit[i] - 1, b = 1;
            while (m)
            {
                t += ++b;
                t %= 998244353;
                m--;
            }
            cout << " " << t << endl;
            rst += t;
            rst %= 998244353;
        }
    }
    cout << rst + n;
    
    return 0;
}
